<template>
	<view class="container">
		<view class="porson-pagebg">
			<image src="../../static/img_my_bg.png" mode="widthFix"></image>
		</view>
		<view class="porson-pageinfo">
			<view class="porson-pageinfo-big">
				<view class="porson-pageinfo-head">
					<view class="porson-pageinfo-headImg">
						<view class="porson-pageinfo-headImgnav">
							<image :src="avatar" mode="widthFix"></image>
						</view>
					</view>
					<view class="porson-pageinfo-headtxt">
						<text>{{username}}</text>
						<text @click="lookinfo">查看个人资料</text>
					</view>
				</view>
				<view class="porson-pageinfo-head-logout" @click="loginout">
					<image src="../../static/ic_out.png" mode=""></image>
				</view>
			</view>
			<view class="porson-pageinfo-part">
				<view class="porson-pageinfo-partItem" @click="paiban">
					<view class="porson-pageinfo-partItemImg">
						<image src="../../static/ic_paian.png" mode="widthFix"></image>
					</view>
					<text>接诊排班</text>
				</view>
				<view class="porson-pageinfo-partItem" @click="renzheng">
					<view class="porson-pageinfo-partItemImg">
						<image src="../../static/ic_renzheng.png" mode="widthFix"></image>
					</view>
					<text>我的认证</text>
				</view>
			</view>
			<view class="porson-pageinfo-part">
				<view class="doc-mi-dai" @click="changestatus(0)" :class="[docstatus == 0?'doc-mi-dai-Sactive':'']">
					<text style="position: relative;">
						待接诊
						<div class="doc-mi-count" v-if="docstatus == 0 && total != 0">{{total}}</div>
					</text>
				</view>
				<view class="doc-mi-dai" @click="changestatus(1)" :class="[docstatus == 1?'doc-mi-dai-Sactive':'']">
					<text>已接诊</text>
				</view>
			</view>
		</view>
		<view class="porson-pageinfo-con">
			<view v-if="docstatus == 0" class="porson-pageinfo-condai">
				<view class="porson-pageinfo-condaiItem" v-for="(item,index) in patientList" :key="index" @click="patinetdetail(item.id,item.status)">
					<view class="porson-pageinfo-condaiItem-t">
						<view class="porson-pageinfo-condaiItem-tL">
							<text>{{item.code}}</text>
							<text>{{item.user_member_name}}</text>
						</view>
						<view class="porson-pageinfo-condaiItem-tR">
							<text>待就诊</text>
							<!-- <text v-if="item.code == 1">已就诊</text> -->
						</view>
					</view>
					<view class="porson-pageinfo-condaiItem-mid">
						<text>{{item.user_member_age}}岁</text>
					</view>
					<view class="porson-pageinfo-condaiItem-b">{{item.make_time}}</view>
				</view>
			</view>
			<view v-if="docstatus == 1" class="porson-pageinfo-coned">
				<view class="porson-pageinfo-condaiItem" v-for="(item,index) in patientList" :key="index" @click="patinetdetail(item.id,item.status)">
					<view class="porson-pageinfo-condaiItem-t">
						<view class="porson-pageinfo-condaiItem-tL">
							<text>{{item.code}}</text>
							<text>{{item.user_member_name}}</text>
						</view>
						<view class="porson-pageinfo-condaiItem-tR">
							<text>已就诊</text>
							<!-- <text v-if="item.code == 1">已就诊</text> -->
						</view>
					</view>
					<view class="porson-pageinfo-condaiItem-mid">
						<text>{{item.user_member_age}}岁</text>
					</view>
					<view class="porson-pageinfo-condaiItem-b">{{item.make_time}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import app from '../../App.vue'
	export default{
		data(){
			return{
				docstatus:0,
				avatar:'',
				username:'',
				page:1,
				patientList:[],
				total:0,
				docId:''
			}
		},
		onLoad() {
			this.getdocinfo()
			this.getpatient()
		},
		onReachBottom() {
			that.page++
			this.getpatient();
		},
		methods:{
			changestatus(num){
				let that = this
				that.total = 0
				that.docstatus = num
				that.$nextTick(function(){
					that.patientList = []
					that.getpatient()
				})
			},
			getdocinfo(){				//医生信息
				let that = this
				app.post('api/user/index','GET').then(res=>{
					if(res.code == 1){
						console.log(res)
						that.avatar = res.data.avatar
						that.username = res.data.nickname
						that.docId = res.data.id 
					}else if(res.code == 0){
						uni.showToast({
							title: res.msg,
							icon: 'none',
							mask: true
						})
					}else if(res.code == 401){
						uni.showToast({
							title: res.msg,
							icon: 'none',
							mask: true
						})
					}
				}).catch(err=>{
					uni.showToast({
						title: err.msg,
						icon: 'none',
						mask: true
					})
				})
			},
			paiban(){
				uni.showLoading({
					title:'加载中',
					success() {
						setTimeout(function(){
							uni.hideLoading()
							uni.navigateTo({
								url:'/pages/doc/paiban'
							})
						},1300)
					}
				})
			},
			renzheng(){
				uni.showLoading({
					title:'加载中',
					success() {
						setTimeout(function(){
							uni.hideLoading()
							uni.navigateTo({
								url:'/pages/doc/renzheng'
							})
						},1300)
					}
				})
			},
			getpatient(){				//接诊列表
				let that = this,
				data = {
					status:that.docstatus == 0?0:that.docstatus,
					page:that.page,
					per_page:10,
				}
				app.post('api/order/getDoctorOrderList',data).then(res=>{
					if(res.code == 1){
						console.log(res)
						that.patientList = res.data.data
						that.total = res.data.total
					}else if(res.code == 0){
						uni.showToast({
							title: res.msg,
							icon: 'none',
							mask: true
						})
					}else if(res.code == 401){
						uni.showToast({
							title: res.msg,
							icon: 'none',
							mask: true
						})
					}
					// that.page++
				}).catch(err=>{
					uni.showToast({
						title: err.msg,
						icon: 'none',
						mask: true
					})
				})
			},
			patinetdetail(id,status){			
				uni.showLoading({
					title:'加载中',
					success() {
						setTimeout(function(){
							uni.hideLoading()
							uni.navigateTo({
								url:'/pages/doc/yuyue?id='+id+'&status='+status
							})
						},1300)
					}
				})
			},
			
			loginout(){				//退出登录
				uni.showModal({
					content:'确定退出登录',
					success(res) {
						if(res.confirm){
							app.post('api/user/logout','GET').then(res=>{
								if(res.code == 1){
									uni.showLoading({
										title:'加载中',
										success() {
											setTimeout(function(){
												uni.hideLoading()
												uni.removeStorageSync('token')
												uni.navigateTo({
													url:'/pages/login/login'
												})
											},1300)
										}
									})
								}
							})
						}
					}
				})
			},
			lookinfo(){
				let that = this
				uni.showLoading({
					title:'加载中',
					success() {
						setTimeout(function(){
							uni.hideLoading()
							uni.navigateTo({
								url:'/pages/doc/lookinfo?id='+that.docId
							})
						},1300)
					}
				})
			}
		}
	}
</script>

<style>
	@import url("../../common/docmine.css");
</style>
